package com.lineage.server.command.executor;

import com.lineage.server.datatables.ItemLimitTable;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import java.util.StringTokenizer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class L1ItemLimitSet implements L1CommandExecutor {
  private static final Log _log = LogFactory.getLog(L1ItemLimitSet.class);
  
  public static L1CommandExecutor getInstance() {
    return new L1ItemLimitSet();
  }
  
  public void execute(L1PcInstance pc, String cmdName, String arg) {
    try {
      StringTokenizer st = new StringTokenizer(arg);
      int itemid = Integer.parseInt(st.nextToken());
      int count = Integer.parseInt(st.nextToken());
      if (ItemLimitTable.TIME.get(Integer.valueOf(itemid)) != null) {
        try {
          ItemLimitTable.get().update2(itemid, count);
          ItemLimitTable.get().load();
        } catch (Exception exception) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage(".itemlimit [物品编号] [限制数量]"));
        } 
      } else {
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("物品限制清单中没有这项编号"));
      } 
    } catch (Exception e) {
      _log.error("错误的GM指令格式: " + getClass().getSimpleName() + " 执行的GM:" + pc.getName());
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(261));
    } 
  }
}
